home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
graphic
/
tpega.zip
/
SIERP.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1986-02-01
|
3KB
|
118 lines
program Sierpinski(input,output);
{This program was taken from N. Wirth, "Algorithms + Data Structures =
Programs, Prentice-Hall, 1976. Further information on Sierpinski curves
may be found in "Creative Computing", July 1984.}
{$U- Change the "-" to a "+" if you want Ctrl-Break to interrupt.}
{The parameters below are set to draw Sierpinski curves up to level 6.
When the "?" appears pressing "x" will exit the program. Pressing any
other key will change the palette.}
const n=6;h0=256;
type AString = String[80];
var i,h,x,y,x0,y0,plotcolor : integer;
{$I GPParms.p }
{$I GPInit.p }
{$I GPTerm.p }
{$I GPPal.p }
{$I GPColor.p }
{$I GPMOVE.P }
{$I GPLINE.P }
{$I GPSCALE.P }
{$I GPCLIP2.P }
{$I GPVIEWPO.P }
{$I GPWINDOW.P }
{$I WORLD.P }
procedure CenterLine(ThisString : AString; xcoord, ycoord: integer);
begin
xcoord := xcoord + 20 - length(ThisString) div 2;
gotoxy(xcoord,ycoord);
write(ThisString);
end;
procedure Initialize;
begin
GPPARMS;
GPInit;
CenterLine('Sierpinski Curve',1,1);
SetWindow(0,0,255,255);
SetViewport(0,14,GDMAXCOL,GDMAXROW);
GPCOLOR(1);
end;
procedure plotline;
begin
GPColor(plotcolor);
LnAbs(x,y);
end;
procedure setplot;
begin
MovAbs(x,y);
end;
procedure A(i:integer); forward;
procedure B(i:integer); forward;
procedure C(i:integer); forward;
procedure D(i:integer); forward;
procedure A;
begin if i > 0 then
begin A(i-1);x:= x+h;y:=y-h;plotline;
B(i-1);x:= x+2*h;plotline;
D(i-1);x:=x+h;y:=y+h;plotline;
A(i-1)
end
end;
procedure B;
begin if i > 0 then
begin B(i-1);x:=x-h;y:=y-h;plotline;
C(i-1);y:=y-2*h;plotline;
A(i-1);x:=x+h;y:=y-h;plotline;
B(i-1)
end
end;
procedure C;
begin if i > 0 then
begin C(i-1);x:=x-h; y:=y+h;plotline;
D(i-1);x:=x-2*h;plotline;
B(i-1);x:=x-h;y:=y-h;plotline;
C(i-1)
end
end;
procedure D;
begin if i > 0 then
begin D(i-1);x:=x+h;y:=y+h;plotline;
A(i-1);y:=y+2*h;plotline;
c(i-1);x:=x-h;y:=y+h;plotline;
D(i-1)
end
end;
begin
initialize;
plotcolor := 1;
i := 0; h:=h0 div 4; x0 := 2*h; y0 :=3*h;
repeat
i:=i+1;x0:=x0-h;
h:=h div 2; y0:=y0+h;
x:=x0;y:=y0;setplot;
A(i);x:=x+h;y:=y-h;plotline;
B(i);x:=x-h;y:=y-h;plotline;
C(i);x:=x-h;y:=y+h;plotline;
D(i);x:=x+h;y:=y+h;plotline;
plotcolor := plotcolor + 1;if plotcolor > 8 then plotcolor := 1;
gotoxy(39,25); write(i);
until i = n;
gotoxy(0,0);
readln;
GPTERM;
end.